package com.payment.ktb.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.payment.ktb.Interface.OnClickTitleBack;
import com.payment.ktb.R;
import com.payment.ktb.utils.ActivityUtils;
import com.payment.ktb.utils.LogUtil;
import com.payment.ktb.utils.ProgressDialogUtils;
import com.umeng.analytics.MobclickAgent;


/**
 * Created by syd on 2016/4/26.
 */
public class BaseActivity extends AppCompatActivity {

    public ProgressDialogUtils progressDialogUtils;
    public Context mContext;
    public RequestQueue mQueue;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        ActivityUtils.addActivity(getClass().getSimpleName(),this);
        mContext = this;
        mQueue = Volley.newRequestQueue(mContext);
        progressDialogUtils = new ProgressDialogUtils(mContext);
        LogUtil.e(this.getClass().getName());
       // LogUtil.e(this.getClass().getName() + "--------->" + "onCreate");
        //关闭软键盘
        InputMethodManager methodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        methodManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
    }


    /**
     * 标题名称
     * @param titleContent
     */
    public void initTitle(String titleContent) {
        TextView tv_title_content = (TextView)findViewById(R.id.tv_title_content);
        tv_title_content.setText(titleContent);
    }

    /**
     * 返回按钮的提示
     * @param titleBackDesc
     */
    public void initBackDesc(String titleBackDesc) {
        TextView tv_title_back_desc = (TextView)findViewById(R.id.tv_title_back_desc);
        tv_title_back_desc.setText(titleBackDesc);
    }

    /**
     * 右边按钮的提示
     * @param titleRight
     */
    public void initRight(String titleRight) {
        TextView tv_title_right = (TextView)findViewById(R.id.tv_title_right);
        tv_title_right.setText(titleRight);
    }


    /**
     * 隐藏返回按钮
     */
    public void hideTitleBack(){
        LinearLayout ll_title_back = (LinearLayout)findViewById(R.id.ll_title_back);
        ll_title_back.setVisibility(View.GONE);
    }

    /**
     * 隐藏返回箭头
     */
    public void hideTitleBackArror(){
        TextView tv_title_back_arror = (TextView)findViewById(R.id.tv_title_back_arror);
        tv_title_back_arror.setVisibility(View.GONE);
    }

    /**
     * 点击返回按钮后的回调事件
     * @param onClickTitleBack
     */
    public void clickTitleBack(final OnClickTitleBack onClickTitleBack){
        LinearLayout ll_title_back = (LinearLayout)findViewById(R.id.ll_title_back);
        ll_title_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickTitleBack.onClick(v);
            }
        });
    }


    /**
     * 监听onTouchEvent事件，
     * 关闭软键盘。getWindow().getDecorView()的意思是获取window的最前面的view。软键盘是phonewindow的根view
     * @param event
     * @return
     */
//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        //关闭软键盘
//        InputMethodManager methodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//        methodManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
//        return super.onTouchEvent(event);
//    }

    /**
     *
     * @param clazz
     */
    public void startActivity(Class clazz) {
        Intent intent = new Intent(this,clazz);
        startActivity(intent);
    }

    /**
     *
     * @param clazz
     */
    public void startActivityThenKill(Class clazz) {
        Intent intent = new Intent(this,clazz);
        startActivity(intent);
        finish();
    }


    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onStart() {
        super.onStart();
        //LogUtil.e(this.getClass().getName() + "--------->" + "onStart");

    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        //LogUtil.e(this.getClass().getName() + "--------->" + "onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
       // LogUtil.e(this.getClass().getName() + "--------->" + "onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
       // LogUtil.e(this.getClass().getName() + "--------->" + "onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityUtils.removeActivity(getClass().getSimpleName());
        //LogUtil.e(this.getClass().getName() + "--------->" + "onDestroy");
    }
}
